package com.information.controller;

import com.information.entity.OperationLog;
import com.information.service.OperationLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/logs")
public class OperationLogController {
    
    private final OperationLogService operationLogService;
    
    @Autowired
    public OperationLogController(OperationLogService operationLogService) {
        this.operationLogService = operationLogService;
    }
    
    @GetMapping
    public ResponseEntity<List<OperationLog>> getAllLogs() {
        List<OperationLog> logs = operationLogService.findAllLogs();
        return ResponseEntity.ok(logs);
    }
    
    @GetMapping("/user/{userId}")
    public ResponseEntity<List<OperationLog>> getLogsByUserId(@PathVariable Long userId) {
        List<OperationLog> logs = operationLogService.findLogsByUserId(userId);
        return ResponseEntity.ok(logs);
    }
    
    @GetMapping("/type/{operationType}")
    public ResponseEntity<List<OperationLog>> getLogsByOperationType(@PathVariable String operationType) {
        List<OperationLog> logs = operationLogService.findLogsByOperationType(operationType);
        return ResponseEntity.ok(logs);
    }
    
    @GetMapping("/username/{username}")
    public ResponseEntity<List<OperationLog>> getLogsByUsername(@PathVariable String username) {
        List<OperationLog> logs = operationLogService.findLogsByUsername(username);
        return ResponseEntity.ok(logs);
    }
} 